<template>
  <div class="app-container">
    <el-form :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      class="form-search"
      label-width="80px">

      <el-form-item label="问题"
        prop="categoryId">
        <el-select v-model="queryParams.categoryId"
          clearable
          placeholder="请选择问题"
          style="width: 240px">
          <el-option v-for="item in problemList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="卦名称"
        prop="guaId">
        <el-select v-model="queryParams.guaId"
          clearable
          placeholder="请选择卦"
          style="width: 240px">
          <el-option v-for="item in guaList"
            :key="item.guaId"
            :label="item.name"
            :value="item.guaId">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="卜卦方法"
        prop="guaMethod">
        <el-select v-model="queryParams.guaMethod"
          placeholder="请选择卜卦方法"
          clearable
          style="width: 240px">
          <el-option key="1"
            label="金钱卦"
            value="金钱卦" />
          <el-option key="0"
            label="大衍筮法"
            value="大衍筮法" />
        </el-select>
      </el-form-item>
      <el-form-item label="请香状态"
        prop="xiangStatus">
        <el-select v-model="queryParams.xiangStatus"
          placeholder="请选择请香状态"
          clearable
          style="width: 240px">
          <el-option key="1"
            label="已请"
            value="0" />
          <el-option key="0"
            label="未请"
            value="0" />
        </el-select>
      </el-form-item>
      <el-form-item label="结缘状态"
        prop="fateStatus">
        <el-select v-model="queryParams.fateStatus"
          placeholder="请选择结缘状态"
          clearable
          style="width: 240px">
          <el-option key="1"
            label="已结缘"
            value="0" />
          <el-option key="0"
            label="未结缘"
            value="0" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery">搜 索</el-button>
        <el-button icon="el-icon-refresh"
          size="mini"
          @click="resetQuery">重 置</el-button>
      </el-form-item>
    </el-form>
    <div class="section-box">

      <el-table v-loading="loading"
        :data="dataList">
        <el-table-column label="客户名称"
          align="center"
          prop="customerName"
          :show-overflow-tooltip="true"
          min-width="160" />
        <el-table-column label="头像"
          align="center"
          prop="headImage"
          :show-overflow-tooltip="true"
          min-width="120">
          <template slot-scope="scope">
            <div>
              <el-image style="width: 50px; height: 50px;"
                :src="scope.row.headImage"
                :preview-src-list="[scope.row.headImage]"
                fit="cover"
                preview-teleported="true" />
            </div>
          </template>
        </el-table-column>
        <el-table-column label="电话"
          align="center"
          prop="phone"
          :show-overflow-tooltip="true"
          min-width="160" />
        <el-table-column label="结缘商品"
          align="center"
          prop="shangName"
          :show-overflow-tooltip="true"
          min-width="160" />
        <el-table-column label="卦名"
          align="center"
          prop="guaName"
          :show-overflow-tooltip="true"
          min-width="160" />
        <el-table-column label="占卜问题"
          align="center"
          prop="categoryName"
          :show-overflow-tooltip="true"
          min-width="160" />
        <el-table-column label="结果"
          align="center"
          prop="result"
          :show-overflow-tooltip="true"
          min-width="160" />
        <el-table-column label="吉凶"
          align="center"
          prop="jiXiong"
          :show-overflow-tooltip="true"
          min-width="160" />
        <el-table-column label="卜卦方式"
          align="center"
          prop="guaMethod"
          :show-overflow-tooltip="true"
          min-width="160" />
        <el-table-column label="高香"
          align="center"
          prop="qingXiang"
          :show-overflow-tooltip="true"
          min-width="160" />
        <el-table-column label="请香状态"
          align="center"
          prop="xiangStatus"
          :show-overflow-tooltip="true"
          min-width="120">
          <template slot-scope="scope">
            <span>{{scope.row.xiangStatus == '1'? '请香': '未请香'}}</span>
          </template>
        </el-table-column>
        <el-table-column label="结缘状态"
          align="center"
          prop="fateStatus"
          :show-overflow-tooltip="true"
          min-width="120">
          <template slot-scope="scope">
            <span>{{scope.row.fateStatus == '1'? '已结缘': '未结缘'}}</span>
          </template>
        </el-table-column>
        <el-table-column label="完成卜卦时间"
          align="center"
          prop="finishTime"
          :show-overflow-tooltip="true"
          min-width="160" />
        <el-table-column label="创建时间"
          align="center"
          prop="createTime"
          :show-overflow-tooltip="true"
          min-width="160" />
      </el-table>

      <pagination v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>

  </div>
</template>

<script>
import {
  getMemberDivinationList,
} from "@/api/member/member.js";
import {
  getProblemList,
} from "@/api/resource/divinationProblem.js";
import {
  getDivinationList,
} from "@/api/divination/divination64.js";
import { onInput } from '@/utils/util.js'

export default {
  name: "MemberDivination",
  data () {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        categoryId: null,
        guaId: null,
        guaMethod: null,
        xiangStatus: null,
        fateStatus: null
      },
      // 数据列表
      dataList: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {},

      problemList: [],
      guaList: []
    };
  },
  created () {
    this.getList();
    this.getProblemData()
    this.getGuaData()
  },
  methods: {
    onInput,
    getProblemData () {
      getProblemList({
        pageNum: 1,
        pageSize: 100,
      }).then(
        (response) => {
          this.problemList = response.rows;
        }
      );
    },
    getGuaData () {
      getDivinationList({
        pageNum: 1,
        pageSize: 100,
      }).then(
        (response) => {
          this.guaList = response.rows;
        }
      );
    },
    /** 查询列表 */
    getList () {
      this.loading = true;
      getMemberDivinationList(this.queryParams).then(
        (response) => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },

  },
};
</script>
